/*
 * $Id: Exception.h,v 1.3 2005-05-02 11:14:47 bacon Exp $
 */

#ifndef _XPP_EXCEPTION_CLASS_
#define _XPP_EXCEPTION_CLASS_

#include <xp/types.h>
#include <xp/macros.h>

namespace xpp
{

#ifdef XP_DEBUG_VERBOSE
	class Exception
	{
	public:
		Exception (
			const xp_char_t* name, const xp_char_t* msg, 
			const xp_char_t* file, int line): 
			name(name), msg(msg), file(file), line(line) {}

		const xp_char_t* name;
		const xp_char_t* msg;
		const xp_char_t* file;
		int   line;
	};

	#define XPP_THROW(ex_name) \
		throw ex_name(XP_QUOTE(ex_name),XP_QUOTE(ex_name), XP_TEXT(__FILE__), __LINE__)
	#define XPP_THROW_WITH_MSG(ex_name,msg) \
		throw ex_name(XP_QUOTE(ex_name),msg, XP_TEXT(__FILE__), __LINE__)

	#define	XPP_EXCEPTION(ex_name) \
		class ex_name: public xpp::Exception {  \
		public: \
			ex_name ( \
				const xp_char_t* name, const xp_char_t* msg, \
				const xp_char_t* file, int line): \
				xpp::Exception (name, msg, file, line) {} \
		}

	#define XPP_EXCEPTION_NAME(exception_object) ((exception_object).name)
	#define XPP_EXCEPTION_MSG(exception_object)  ((exception_object).msg)
	#define XPP_EXCEPTION_FILE(exception_object) ((exception_object).file)
	#define XPP_EXCEPTION_LINE(exception_object) ((exception_object).line)
#else

	class Exception 
	{
	public:
		Exception (const xp_char_t* name, const xp_char_t* msg):
			name(name), msg(msg) {}

		const xp_char_t* name;
		const xp_char_t* msg;
	};

	#define XPP_THROW(ex_name) \
		throw ex_name(XP_QUOTE(ex_name),XP_QUOTE(ex_name))
	#define XPP_THROW_WITH_MSG(ex_name,msg) \
		throw ex_name(XP_QUOTE(ex_name),msg)

	#define	XPP_EXCEPTION(ex_name) \
		class ex_name: public xpp::Exception {  \
		public: \
			ex_name (const xp_char_t* name, const xp_char_t* msg): \
				xpp::Exception (name, msg) {} \
		}

	#define XPP_EXCEPTION_NAME(exception_object) ((exception_object).name)
	#define XPP_EXCEPTION_MSG(exception_object)  ((exception_object).msg)
	#define XPP_EXCEPTION_FILE(exception_object) (XP_TEXT(""))
	#define XPP_EXCEPTION_LINE(exception_object) (0)

#endif

}

#endif
